package swingtest;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class J_GridBagLayout {

	public static void main(String[] args) {
		JFrame app = new JFrame("J_GridBagLayout");
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		app.setSize(320, 160);
		app.setLocationByPlatform(true);
		Container container = app.getContentPane();

		GridBagLayout gr = new GridBagLayout();
		container.setLayout(gr);

		GridBagConstraints gc = new GridBagConstraints();

		int[] gx = { 0, 1, 2, 3, 1, 0, 0, 2 };
		int[] gy = { 0, 0, 0, 0, 1, 2, 3, 2 };
		int[] gw = { 1, 1, 1, 1, GridBagConstraints.RELATIVE, 2, 2, 2 };
		int[] gh = { 2, 1, 1, 1, 1, 1, 1, 2 };
		for (int i = 0; i < gh.length; i++) {
			JButton b = new JButton("button" + i);
			gc.gridx = gx[i];
			gc.gridy = gy[i];
			gc.gridwidth = gw[i];
			gc.gridheight = gh[i];
			gc.fill = GridBagConstraints.BOTH;
			gr.setConstraints(b, gc);
			container.add(b);
		}
		
		JButton b = new JButton("button2323");
		gc.gridx = 4;
		gc.gridy = 0;
		gc.gridwidth = 4;
		gc.gridheight = 4;
		gc.fill = GridBagConstraints.BOTH;
		gr.setConstraints(b, gc);
		container.add(b);
		
		app.setVisible(true);

	}

}
